package com.nuonuo.controller;

import com.nuonuo.listener.OrderCallBackListener;
import com.nuonuo.queue.RedisDelayedQueue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author duan
 * @version 1.0
 * @date 2024/1/25 16:49
 */
@RequestMapping(value = "redisson")
@RestController
public class RedissonController {

    private static final Logger LOGGER = LoggerFactory.getLogger(RedissonController.class);

    private static final AtomicInteger COUNT = new AtomicInteger(0);
    private static final AtomicInteger MANY_COUNT = new AtomicInteger(0);
    @Resource
    private RedisDelayedQueue redisDelayedQueue;

    @GetMapping(value = "/put")
    public String put() {
        String value = COUNT.incrementAndGet() + "";
        redisDelayedQueue.addQueueSeconds(value, 30, OrderCallBackListener.class);
        LOGGER.info("### put value: " + value);
        return "OK";
    }



    @GetMapping(value = "/putMany")
    public String putMany(int num) {
        for (int i = 0; i < num; i++) {
            String value = MANY_COUNT.incrementAndGet() + "%%";
            redisDelayedQueue.addQueueSeconds(value, 5, OrderCallBackListener.class);
            LOGGER.info("### put value: " + value);
        }
        return "OK";
    }
}
